<html>
<head><meta charset="utf-8"><title>type layout for references to unsized types · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html">type layout for references to unsized types</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231688275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231688275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231688275">(Mar 24 2021 at 18:48)</a>:</h4>
<p>Hey is <span class="user-mention" data-user-id="119009">@eddyb</span> around? Or is it too late a night where they are?</p>



<a name="231688548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231688548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231688548">(Mar 24 2021 at 18:50)</a>:</h4>
<p>What's the question?</p>



<a name="231688903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231688903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231688903">(Mar 24 2021 at 18:52)</a>:</h4>
<p>I got some questions about how to tell, in the compiler, whether the metadata for a fat pointer is for a slice length or for a vtable pointer</p>



<a name="231688993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231688993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231688993">(Mar 24 2021 at 18:52)</a>:</h4>
<p>from skimming the code in rustc_target/src/abi/mod.rs, it seems like we are leveraging the fact that both of those have the same size, and just using “Scalar” for both cases</p>



<a name="231689059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231689059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231689059">(Mar 24 2021 at 18:53)</a>:</h4>
<p>does that sound accurate? As in, there’s currently no trivial way to answer that question? Or am I overlooking some utility function?</p>



<a name="231690261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690261">(Mar 24 2021 at 19:00)</a>:</h4>
<p>does it need to involve layout?</p>



<a name="231690366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690366">(Mar 24 2021 at 19:01)</a>:</h4>
<p>well, maybe it doesn't</p>



<a name="231690390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690390">(Mar 24 2021 at 19:01)</a>:</h4>
<p>I think the reason it involves layout</p>



<a name="231690411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690411">(Mar 24 2021 at 19:01)</a>:</h4>
<p>is that this developer is effectively writing an alternative backend</p>



<a name="231690541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690541">(Mar 24 2021 at 19:02)</a>:</h4>
<p>and they want to 1. be sure that they are making the right kind of layout (i.e. that they are putting the metadata into the right place), and</p>



<a name="231690670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690670">(Mar 24 2021 at 19:03)</a>:</h4>
<ol start="2">
<li>accommodate their particular target, and their particular target does not want to conflate the two kinds of Scalars here</li>
</ol>



<a name="231690736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690736">(Mar 24 2021 at 19:03)</a>:</h4>
<p>(essentially they need to reflect the fact that they’re dealing with a length versus a vtable-pointer explicitly)</p>



<a name="231690809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690809">(Mar 24 2021 at 19:04)</a>:</h4>
<p>so the layout is relevant to part 1</p>



<a name="231690839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231690839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231690839">(Mar 24 2021 at 19:04)</a>:</h4>
<p>while the original question is more about part 2</p>



<a name="231691486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231691486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231691486">(Mar 24 2021 at 19:08)</a>:</h4>
<p>So, in the LLVM backend at least we do generate pointer or <code>u64</code> as appropriate for the metadata part of the fat pointer.</p>



<a name="231692111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231692111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231692111">(Mar 24 2021 at 19:13)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/f5fe425c925ef36d5f4c18cfa44173fc42de31b8/compiler/rustc_codegen_llvm/src/type_of.rs#L303-L341">https://github.com/rust-lang/rust/blob/f5fe425c925ef36d5f4c18cfa44173fc42de31b8/compiler/rustc_codegen_llvm/src/type_of.rs#L303-L341</a> is the relevant code, I believe, so we indeed end up looking at plain <code>Ty</code>s to figure it out, rather than layouts.</p>



<a name="231692319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231692319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231692319">(Mar 24 2021 at 19:15)</a>:</h4>
<p>Or, I should say, that's what it looks like we're doing after a very quick read.</p>



<a name="231692621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231692621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231692621">(Mar 24 2021 at 19:17)</a>:</h4>
<p>does the <code>index</code> parameter there control wheter it returns the data-ptr or the metadata value?</p>



<a name="231692648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231692648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231692648">(Mar 24 2021 at 19:17)</a>:</h4>
<p>Yes. <code>0</code> is for the data, and <code>1</code> is for the metadata.</p>



<a name="231692977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231692977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231692977">(Mar 24 2021 at 19:19)</a>:</h4>
<p>And <a href="https://rust.godbolt.org/z/Tn8MK7n35">https://rust.godbolt.org/z/Tn8MK7n35</a> is a demonstration that we end up generating distinct-looking types in the backend _somewhere_.</p>



<a name="231693065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231693065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231693065">(Mar 24 2021 at 19:20)</a>:</h4>
<p>namely <code>{ {}*, [3 x i64]* }</code> vs <code>{ [0 x i8]*, i64 }</code></p>



<a name="231702573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231702573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231702573">(Mar 24 2021 at 20:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types/near/231690411">said</a>:</p>
<blockquote>
<p>is that this developer is effectively writing an alternative backend</p>
</blockquote>
<p>are they trying to be ABI compatible? (which is unspecified, of course) otherwise, they can decide as they like</p>



<a name="231706156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231706156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231706156">(Mar 24 2021 at 20:50)</a>:</h4>
<p>I think they are likely trying to be ABI-compatible, but that is a good question.</p>



<a name="231788997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231788997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231788997">(Mar 25 2021 at 12:09)</a>:</h4>
<p>If they are trying to be ABI-compatible, they only need the pass mode for said argument from the <code>FnAbi</code>. The types used inside the function don't matter for ABI compatibility. Only the types used when passing as argument matter. These types are often fundamentally different from the internal types. Especially when using <code>PassMode::Cast</code>.</p>



<a name="231789122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20layout%20for%20references%20to%20unsized%20types/near/231789122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20layout.20for.20references.20to.20unsized.20types.html#231789122">(Mar 25 2021 at 12:10)</a>:</h4>
<p>The abi handling code in cg_clif is easier to read than the cg_llvm counterpart IMO: <a href="https://github.com/bjorn3/rustc_codegen_cranelift/blob/73626efb26f61c68c8c9d4bec0a35928130a2010/src/abi/">https://github.com/bjorn3/rustc_codegen_cranelift/blob/73626efb26f61c68c8c9d4bec0a35928130a2010/src/abi/</a> Cranelift doesn't distinguish between pointers and pointer sized integers though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>